<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="电影名">
        <el-input v-model="form.nfName" />
      </el-form-item>
      <el-form-item label="演员名">
        <el-input v-model="form.nfActor" />
      </el-form-item>
      <el-form-item label="电影图地址">
        <el-input v-model="form.nfImg" />
      </el-form-item>
      <el-form-item label="价格">
        <el-input v-model="form.nfPrice" />
      </el-form-item>
      <el-form-item label="时长">
        <el-input v-model="form.nfLongtime" />
      </el-form-item>
      <el-form-item label="导演">
        <el-input v-model="form.nfDirector"  />
      </el-form-item>
      <el-form-item>
        <el-form-item label="是否在首页显示">
          <el-select v-model="form.nfIshow" placeholder="是">
            <el-option label="是" value="1" />
            <el-option label="否" value="0" />
          </el-select>
        </el-form-item>

        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import Qs from 'qs'
  export default {
    data() {
      return {
        form: {
          nfId:'',nfName:'',nfDirector:'',nfActor:'',nfLongtime:'', nfPrice:'',nfImg:'',nfIshow:''
        }
      }
    },
    methods: {

      onSubmit() {
        var vm =this
        this.$confirm('此操作是添加电影信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios({
            url:'http://localhost:80/api/nextfilm/addfilm',
            method:'post',
            transformRequest: [function (data) {
              return Qs.stringify(data)
            }],
            data:this.form
          }).then(function(res) {
            if(res.data.success){
              vm.$message('添加成功!')
              vm.$router.push({name:'nextfilm'})
            } else{
              vm.$message('添加失败!')
            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      },
      onCancel() {
        this.$message({
          message: 'cancel!',
          type: 'warning'
        })
      }
    },
    created() {
    }
  }
</script>

<style scoped>
  .line{
    text-align: center;
  }
</style>

